﻿
module("FallingS.init")
test("FallingS init", function () {
    var x = 5;
    var y = 6;
    var color = "#FF00FF";

    var fallingS = new tetris.FallingS(x, y, color);
    equal(5, fallingS.center.x, "CenterX of FallingS is set");
    equal(6, fallingS.center.y, "CenterY of FallingS is set");

    var relativeBody="";
    for (var i = 0; i < fallingS._relativeBody.length; i++) {
        relativeBody += fallingS._relativeBody[i].coordinate.toString() + " ";
    }
    equal("(-1,0) (0,0) (0,1) (1,1) ", relativeBody, "CenterY of FallingS is set");

    var body= "";
    for (var i = 0; i < fallingS.getBody.length; i++) {
        body += fallingS.getBody[i].coordinate.toString() + " ";
    }
    equal("(4,6) (5,6) (5,7) (6,7) ", body, "CenterY of FallingS is set");
});

test("FallingS moveTo", function () {
    var x = 5;
    var y = 6;
    var color = "#FF00FF";

    var fallingS = new tetris.FallingS(x, y, color);
    fallingS.moveTo(7, 8);

    deepEqual(7, fallingS.center.x, "CenterX of FallingS is set to new x");
    equal(8, fallingS.center.y, "CenterY of FallingS is set to new y");

    var relativeBody = "";
    for (var i = 0; i < fallingS._relativeBody.length; i++) {
        relativeBody += fallingS._relativeBody[i].coordinate.toString() + " ";
    }
    equal("(-1,0) (0,0) (0,1) (1,1) ", relativeBody, "CenterY of FallingS is set");

    var body = "";
    for (var i = 0; i < fallingS.getBody.length; i++) {
        body += fallingS.getBody[i].coordinate.toString() + " ";
    }
    equal("(6,8) (7,8) (7,9) (8,9) ", body, "CenterY of FallingS is set");
});

test("FallingS moveRight", function () {
    var x = 5;
    var y = 8;
    var color = "#FF00FF";

    var fallingS = new tetris.FallingS(x, y, color);
    fallingS.moveRight(); 
    deepEqual(6, fallingS.center.x, "CenterX of FallingS is set to x+1");
    equal(8, fallingS.center.y, "CenterY of FallingS is same");
});

test("FallingS moveLeft", function () {
    var x = 5;
    var y = 8;
    var color = "#FF00FF";

    var fallingS = new tetris.FallingS(x, y, color);
    fallingS.moveLeft();
    deepEqual(4, fallingS.center.x, "CenterX of FallingS is set to x-1");
    equal(8, fallingS.center.y, "CenterY of FallingS is same");
});

test("FallingS moveUp", function () {
    var x = 5;
    var y = 8;
    var color = "#FF00FF";

    var fallingS = new tetris.FallingS(x, y, color);
    fallingS.moveUp();
    equal(5, fallingS.center.x, "CenterX of FallingS is same");
    equal(7, fallingS.center.y, "CenterY of FallingS is set to y-1");
});

test("FallingS moveDown", function () {
    var x = 5;
    var y = 8;
    var color = "#FF00FF";

    var fallingS = new tetris.FallingS(x, y, color);
    fallingS.moveDown();
    equal(5, fallingS.center.x, "CenterX of FallingS is same");
    equal(9, fallingS.center.y, "CenterY of FallingS is set to y+1");
});

test("FallingS rotate", function () {
    var x = 5;
    var y = 6;
    var color = "#FF00FF";

    var fallingS = new tetris.FallingS(x, y, color);
    fallingS.rotate();
    equal(90, fallingS.rotation, "Rotation of FallingS is set to 90");
});

test("FallingS rotate twice", function () {
    var x = 5;
    var y = 6;
    var color = "#FF00FF";

    var fallingS = new tetris.FallingS(x, y, color);
    fallingS.rotate();
    equal(90, fallingS.rotation, "Rotation of FallingS is set to 90");
    fallingS.rotate();
    equal(180, fallingS.rotation, "Rotation of FallingS is set to 180");
});

test("FallingS rotateBack", function () {
    var x = 5;
    var y = 6;
    var color = "#FF00FF";

    var fallingS = new tetris.FallingS(x, y, color);
    fallingS.rotateBack();
    equal(270, fallingS.rotation, "Rotation of FallingS is set to 270");   
});

test("FallingS rotateTo", function () {
    var x = 5;
    var y = 6;
    var color = "#FF00FF";

    var fallingS = new tetris.FallingS(x, y, color);
    fallingS.rotateTo(180);
    equal(180, fallingS.rotation, "Rotation of FallingS is set to 180");
});

